// Knockout Mapping plugin v0.5
// (c) 2010 Steven Sanderson, Roy Jacobs - http://knockoutjs.com/
// License: Ms-Pl (http://www.opensource.org/licenses/ms-pl.html)

ko.exportSymbol = function (n, s) { for (var j = n.split("."), t = window, o = 0; o < j.length - 1; o++) t = t[j[o]]; t[j[j.length - 1]] = s }; ko.exportProperty = function (n, s, j) { n[s] = j };
(function () {
    function n(a) { if (a && typeof a === "object" && a.constructor == (new Date).constructor) return "date"; return typeof a } function s(a, c, b) { w || (z = []); w++; a = j(a, c, b); w--; return a } function j(a, c, b, d, f, p) {
        var h = ko.utils.unwrapObservable(c) instanceof Array; if (ko.mapping.isMapped(a)) b = ko.utils.unwrapObservable(a)[q]; d = d || new A; if (d.get(c)) return a; f = f || ""; if (h) {
            p = []; var g = function (e) { return e }; if (b[f] && b[f].key) g = b[f].key; if (!ko.isObservable(a)) {
                a = ko.observableArray([]); a.mappedRemove = function (e) {
                    var i =
typeof e == "function" ? e : function (k) { return k === g(e) }; return a.remove(function (k) { return i(g(k)) })
                }; a.mappedRemoveAll = function (e) { var i = v(e, g); return a.remove(function (k) { return ko.utils.arrayIndexOf(i, g(k)) != -1 }) }; a.mappedDestroy = function (e) { var i = typeof e == "function" ? e : function (k) { return k === g(e) }; return a.destroy(function (k) { return i(g(k)) }) }; a.mappedDestroyAll = function (e) { var i = v(e, g); return a.destroy(function (k) { return ko.utils.arrayIndexOf(i, g(k)) != -1 }) }; a.mappedIndexOf = function (e) {
                    var i = v(a(),
g); e = g(e); return ko.utils.arrayIndexOf(i, e)
                } 
            } h = v(ko.utils.unwrapObservable(a), g).sort(); var r = v(c, g).sort(); h = ko.utils.compareArrays(h, r); r = []; for (var x = 0, C = h.length; x < C; x++) {
                var u = h[x]; switch (u.status) {
                    case "added": var l = o(ko.utils.unwrapObservable(c), u.value, g), m = ko.utils.unwrapObservable(j(undefined, l, b, d, f, a)); l = ko.utils.arrayIndexOf(ko.utils.unwrapObservable(c), l); r[l] = m; break; case "retained": l = o(ko.utils.unwrapObservable(c), u.value, g); m = o(a, u.value, g); j(m, l, b, d, f, a); l = ko.utils.arrayIndexOf(ko.utils.unwrapObservable(c),
l); r[l] = m; break; case "deleted": m = o(a, u.value, g); a.remove(m)
                } p.push({ event: u.status, item: m })
            } a(r); b[f] && b[f].arrayChanged && ko.utils.arrayForEach(p, function (e) { b[f].arrayChanged(e.event, e.item) })
        } else if (n(c) == "object" && c !== null && c !== undefined) { if (!a) if (b[f] && b[f].create instanceof Function) { D(); m = b[f].create({ data: c, parent: p }); ko.dependentObservable = y; return m } else a = {}; d.save(c, a); B(c, function (e) { var i = d.get(c[e]); a[e] = i ? i : j(a[e], c[e], b, d, e, a) }) } else switch (n(c)) {
            case "function": a = c; break; default: if (ko.isWriteableObservable(a)) a(ko.utils.unwrapObservable(c));
                else a = ko.observable(ko.utils.unwrapObservable(c))
        } return a
    } function t(a, c) { var b; if (c) b = c(a); b || (b = a); return ko.utils.unwrapObservable(b) } function o(a, c, b) { a = ko.utils.arrayFilter(ko.utils.unwrapObservable(a), function (d) { return t(d, b) == c }); if (a.length != 1) throw Error("When calling ko.update*, the key '" + c + "' was not found or not unique!"); return a[0] } function v(a, c) { return ko.utils.arrayMap(ko.utils.unwrapObservable(a), function (b) { return c ? t(b, c) : b }) } function B(a, c) {
        if (a instanceof Array) for (var b =
0; b < a.length; b++) c(b); else for (b in a) c(b)
    } function A() { var a = [], c = []; this.save = function (b, d) { var f = ko.utils.arrayIndexOf(a, b); if (f >= 0) c[f] = d; else { a.push(b); c.push(d) } }; this.get = function (b) { b = ko.utils.arrayIndexOf(a, b); return b >= 0 ? c[b] : undefined } } ko.mapping = {}; var q = "__ko_mapping__", w = 0, y = ko.dependentObservable, z; ko.mapping.fromJS = function (a, c, b) {
        if (arguments.length == 0) throw Error("When calling ko.fromJS, pass the object you want to convert."); var d = c; d = d || {}; if (d.create instanceof Function || d.key instanceof
Function || d.arrayChanged instanceof Function) d = { "": d }; c = d; d = s(b, a, c); d[q] = d[q] || {}; d[q] = c; return d
    }; ko.mapping.fromJSON = function (a, c) { var b = ko.utils.parseJson(a); return ko.mapping.fromJS(b, c) }; ko.mapping.isMapped = function (a) { return (a = ko.utils.unwrapObservable(a)) && a[q] }; ko.mapping.updateFromJS = function (a, c) {
        if (arguments.length < 2) throw Error("When calling ko.updateFromJS, pass: the object to update and the object you want to update from."); if (!a) throw Error("The object is undefined."); if (!a[q]) throw Error("The object you are trying to update was not created by a 'fromJS' or 'fromJSON' mapping.");
        return s(a, c, a[q])
    }; ko.mapping.updateFromJSON = function (a, c, b) { c = ko.utils.parseJson(c); return ko.mapping.updateFromJS(a, c, b) }; ko.mapping.toJS = function (a, c) { if (arguments.length == 0) throw Error("When calling ko.mapping.toJS, pass the object you want to convert."); c = c || {}; c.ignore = c.ignore || []; if (!(c.ignore instanceof Array)) c.ignore = [c.ignore]; c.ignore.push(q); return ko.mapping.visitModel(a, function (b) { return ko.utils.unwrapObservable(b) }, c) }; ko.mapping.toJSON = function (a, c) {
        var b = ko.mapping.toJS(a); return ko.utils.stringifyJson(b,
c)
    }; var D = function () { ko.dependentObservable = function (a, c, b) { b = b || {}; b.deferEvaluation = true; a = new y(a, c, b); a.__ko_proto__ = y; z.push(a); return a } }; ko.mapping.visitModel = function (a, c, b) {
        b = b || {}; b.visitedObjects = b.visitedObjects || new A; var d, f = ko.utils.unwrapObservable(a); if (n(f) == "object" && f !== null && f !== undefined) { c(a, b.parentName); d = f instanceof Array ? [] : {} } else return c(a, b.parentName); b.visitedObjects.save(a, d); var p = b.parentName; B(f, function (h) {
            if (!(b.ignore && ko.utils.arrayIndexOf(b.ignore, h) != -1)) {
                var g =
f[h]; b.parentName = p || ""; if (f instanceof Array) { if (p) b.parentName += "[" + h + "]" } else { if (p) b.parentName += "."; b.parentName += h } switch (n(ko.utils.unwrapObservable(g))) { case "object": case "undefined": var r = b.visitedObjects.get(g); d[h] = r !== undefined ? r : ko.mapping.visitModel(g, c, b); break; default: d[h] = c(g, b.parentName) } 
            } 
        }); return d
    }; ko.exportSymbol("ko.mapping", ko.mapping); ko.exportSymbol("ko.mapping.fromJS", ko.mapping.fromJS); ko.exportSymbol("ko.mapping.fromJSON", ko.mapping.fromJSON); ko.exportSymbol("ko.mapping.isMapped",
ko.mapping.isMapped); ko.exportSymbol("ko.mapping.toJS", ko.mapping.toJS); ko.exportSymbol("ko.mapping.toJSON", ko.mapping.toJSON); ko.exportSymbol("ko.mapping.updateFromJS", ko.mapping.updateFromJS); ko.exportSymbol("ko.mapping.updateFromJSON", ko.mapping.updateFromJSON); ko.exportSymbol("ko.mapping.visitModel", ko.mapping.visitModel)
})();